package spring.cloud.tasks.common.task_item_allot;

import com.alibaba.fastjson2.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;


@Slf4j
@Setter
@Getter
public class TaskItem {
    public static final String TASK_TYPE_ITEM_TASK = "item_task";
    public static final String TASK_TYPE_MESSAGE_TASK = "message_task";
    public static final String TASK_TYPE_BATCH_TASK = "batch_task";
    private String taskType;
    private String taskId;
    private String signature;//签名  签名一旦改变那么则需要重新进行任务分配
    private String taskInstanceId;
    private String taskRoundId;//轮次id=任务实例#时间戳 一个任务实例同一时刻只能跑一个，可以支持重跑。
    private int taskItemIndex;
    private int loadLevel;
    @JSONField(name = "nextFireDate", format = "yyyy-MM-dd HH:mm:ss")
    private Date nextFireDate;//指的是可以触发的时间
    @JSONField(name = "timeoutDateTime", format = "yyyy-MM-dd HH:mm:ss")
    private Date timeoutDateTime;//超时时间
    @JSONField(name = "lockDateTime")
    private Date lockDateTime;//锁时间 lockDateTime>timeoutDateTime 每个时间片需要详细记录对应的时间  因为这个是多实例，即最新的分配信息 不一定是最新的分配信息

    public void copy(TaskItem $taskItem) {
        $taskItem.taskType = this.taskType;
        $taskItem.taskId = this.taskId;
        $taskItem.taskInstanceId = this.taskInstanceId;
        $taskItem.taskRoundId = this.taskRoundId;
        $taskItem.taskItemIndex = this.taskItemIndex;
        $taskItem.loadLevel = this.loadLevel;
        $taskItem.nextFireDate = this.nextFireDate;
        $taskItem.timeoutDateTime = this.timeoutDateTime;
        $taskItem.lockDateTime = this.lockDateTime;
    }
}
